<template>
  <div class="a">
     <div v-if="address == 0" @click="goAddress">请选择你的地址</div>
      <div v-if="address == 1" @click="goAddress">
         <div class="message">
          <div>{{info.name }}</div>
          <div>{{info.address}}</div>
          <div>{{info.phone}}</div> 
         </div>
      </div>
    <ul>
      <li v-for="(item, index) in orderlist" :key="index" class="flex-r-b">
        <img :src="item.pro_img" />
        <p>￥{{ item.pro_price }}</p>
      </li>
    </ul>
    <van-submit-bar :price="total" button-text="提交订单" @submit="onSubmit">
    </van-submit-bar>
  </div>
</template>
<script>
import { fapi,fapi1 } from "@/assets/js/farmapi.js";
export default {
  data() {
    return {
      orderlist: null,
      info: {},
      obj:{},
      total:0,
      address:0
    };
  },
  mounted() {
    this.orderlist = this.$store.state.orderlist;
   
    this.getAddress();
  },
  methods: {
    goAddress() {
      this.$router.push("/addressAll");
    },
    onSubmit() {
     this.orderlist.forEach((item) => {
     let a = [
     {
     userId: item.userId,
     pro_num: item.pro_num,
     pro_id: item.pro_id,
    statue: 0, //默认0 待付款
    address_id: this.$route.query.address_id,
     remark: "留言",
 },
 ];
 let o = JSON.stringify(a);
 fapi1("api/createorder", { obj: o }, "post").then((res) => {
 
 });
     });
     
     },
    getAddress() {
      let data = {
        userId: sessionStorage.getItem("islogin"),
      };
      fapi("api/listaddress", data).then((res) => {
        if (res.data.data == "") {
          this.address = 0;
        } else {
          this.address = 1;
        }
    if (this.$route.query.address_id) {
          for (let x in res.data.data) {
            if (res.data.data[x].address_id == this.$route.query.address_id) {
              this.info = res.data.data[x];
            }
          }
        } else {
         for(let x in res.data.data){
           if(res.data.data[x].moren ==1){
             this.info =res.data.data[x];
           }
         }
          
        }
      });
    },
   
  },
};
</script>
<style lang="less" scoped>
img {
  width: 200px;
}
.p{
    font-size: 40px;
}
.message{
  display: flex;
  margin-bottom: 50px;
  margin-top: 20px;
}
.message div{
  margin-left: 50px;
}
ul{
  margin-bottom: 200px;
}
</style>